"use strict";
const common_vendor = require("../../../common/vendor.js");
const common_assets = require("../../../common/assets.js");
const api_complaint_index = require("../../../api/complaint/index.js");
const stores_userInfo = require("../../../stores/userInfo.js");
if (!Array) {
  const _easycom_up_icon2 = common_vendor.resolveComponent("up-icon");
  const _easycom_up_input2 = common_vendor.resolveComponent("up-input");
  const _easycom_up_grid_item2 = common_vendor.resolveComponent("up-grid-item");
  const _easycom_up_grid2 = common_vendor.resolveComponent("up-grid");
  const _easycom_qiun_data_charts2 = common_vendor.resolveComponent("qiun-data-charts");
  const _easycom_uni_th2 = common_vendor.resolveComponent("uni-th");
  const _easycom_uni_tr2 = common_vendor.resolveComponent("uni-tr");
  const _easycom_uni_td2 = common_vendor.resolveComponent("uni-td");
  const _easycom_uni_table2 = common_vendor.resolveComponent("uni-table");
  const _easycom_up_toast2 = common_vendor.resolveComponent("up-toast");
  (_easycom_up_icon2 + _easycom_up_input2 + _easycom_up_grid_item2 + _easycom_up_grid2 + _easycom_qiun_data_charts2 + _easycom_uni_th2 + _easycom_uni_tr2 + _easycom_uni_td2 + _easycom_uni_table2 + _easycom_up_toast2)();
}
const _easycom_up_icon = () => "../../../node-modules/uview-plus/components/u-icon/u-icon.js";
const _easycom_up_input = () => "../../../node-modules/uview-plus/components/u-input/u-input.js";
const _easycom_up_grid_item = () => "../../../node-modules/uview-plus/components/u-grid-item/u-grid-item.js";
const _easycom_up_grid = () => "../../../node-modules/uview-plus/components/u-grid/u-grid.js";
const _easycom_qiun_data_charts = () => "../../../uni_modules/qiun-data-charts/components/qiun-data-charts/qiun-data-charts.js";
const _easycom_uni_th = () => "../../../uni_modules/uni-table/components/uni-th/uni-th.js";
const _easycom_uni_tr = () => "../../../uni_modules/uni-table/components/uni-tr/uni-tr.js";
const _easycom_uni_td = () => "../../../uni_modules/uni-table/components/uni-td/uni-td.js";
const _easycom_uni_table = () => "../../../uni_modules/uni-table/components/uni-table/uni-table.js";
const _easycom_up_toast = () => "../../../node-modules/uview-plus/components/u-toast/u-toast.js";
if (!Math) {
  (_easycom_up_icon + _easycom_up_input + _easycom_up_grid_item + _easycom_up_grid + _easycom_qiun_data_charts + _easycom_uni_th + _easycom_uni_tr + _easycom_uni_td + _easycom_uni_table + _easycom_up_toast)();
}
const _sfc_main = /* @__PURE__ */ common_vendor.defineComponent({
  __name: "index",
  setup(__props) {
    const userInfoStore = stores_userInfo.useUserInfoStore();
    const uToastRef = common_vendor.ref(null);
    const data = common_vendor.reactive({
      showPicker: false,
      queryParam: {
        type: 0,
        // 0按月 1按年
        yearMonth: common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY-MM"),
        policeLeaderId: userInfoStore.userInfo.userId,
        communityId: null
      },
      timeStr: common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年MM月"),
      tableList: []
    });
    const { showPicker, queryParam, timeStr, tableList } = common_vendor.toRefs(data);
    const complaintStatistics = common_vendor.ref([
      {
        num: 0,
        title: "全部投诉",
        color: "#038AFE",
        bgColor0: "#FEF9EC",
        bgColor1: "#FFFCF7"
      },
      {
        num: 0,
        title: "有效投诉",
        color: "#61D3C0",
        bgColor0: "#F9FEFD",
        bgColor1: "#F3FFFB"
      },
      {
        num: 0,
        title: "无效投诉",
        color: "#F55300",
        bgColor0: "#F3F9FE",
        bgColor1: "#EEF6FC"
      },
      {
        num: "0%",
        title: "环比",
        color: "#000000",
        bgColor0: "#FEF6F3",
        bgColor1: "#FEEFEB"
      }
    ]);
    const chartParam = common_vendor.reactive({
      opts: {
        animation: false,
        // 关闭动画
        update: true,
        // 关键：是否开启连续更新数据的方法,开启之后就不会抖动了
        duration: 0,
        // 关闭动画过度
        padding: [10, 5, 5, 0],
        enableScroll: false,
        //true,
        legend: { show: false },
        dataLabel: false,
        // 不显示数据标签
        xAxis: {
          rotateLabel: true,
          // 启用旋转功能减少横向空间占
          rotateAngle: 45,
          // 文字旋转的角度，取值范围(-90至90)
          // scrollShow: true,
          // itemCount: 8,
          interval: 0,
          boundaryGap: "justify",
          // 让柱状图两端不留空白
          disableGrid: true,
          //不绘制纵向网格
          fontColor: "#000000",
          //字体颜色
          fontSize: 10,
          //字体大小
          axisLineColor: "#707070",
          //坐标轴轴线颜色
          marginTop: "5",
          //X轴文字距离轴线的距离
          // labelCount: 6, //数据点文字单屏幕限制显示的数量
          formatter: function(value, index, opts) {
            return value;
          }
        },
        yAxis: {
          disableGrid: true,
          //不绘制横向向网格
          data: [
            {
              min: 0,
              calibration: true,
              //刻度线是否显示
              fontColor: "#8A8A8A",
              //字体颜色
              fontSize: 12,
              //字体大小
              axisLineColor: "#707070"
              //坐标轴轴线颜色
            }
          ]
        },
        extra: {
          column: {
            type: "group",
            width: 10,
            linearType: "custom",
            //渐变类型
            customColor: ["#88C5EC", "#4299FE"],
            activeBgColor: "#000000",
            //当前点击柱状图的背景颜色
            activeBgOpacity: 0.08
            //当前点击柱状图的背景颜色透明度
          }
        }
      },
      chartData: {}
    });
    const getComplaintStat = () => {
      api_complaint_index.complaintStat(queryParam.value).then((res) => {
        const { data: data2 } = res;
        complaintStatistics.value[0].num = data2.sumCount ?? 0;
        complaintStatistics.value[1].num = data2.invalidCount ?? 0;
        complaintStatistics.value[2].num = data2.effectiveCount ?? 0;
        complaintStatistics.value[3].num = data2.sumPercentage ?? "0%";
        if (queryParam.value.type == 1) {
          complaintStatistics.value[3].title = "同比";
        } else {
          complaintStatistics.value[3].title = "环比";
        }
        if (queryParam.value.type == 1) {
          data2.cltCmyChartVos = data2.cltCmyChartVos ?? [];
          let xdata = [];
          let ydata = [];
          if (data2.cltCmyChartVos.length) {
            data2.cltCmyChartVos.forEach((item) => {
              xdata.push(item.communityName);
              ydata.push(+item.communityCount);
            });
          }
          let seriesData = {
            categories: xdata,
            series: [
              {
                name: "投诉次数",
                data: ydata
              }
            ]
          };
          chartParam.chartData = JSON.parse(JSON.stringify(seriesData));
        }
        tableList.value = data2.cltTableVos ?? [];
      }).catch((err) => {
        uToastRef.value.show({
          type: "error",
          message: err
        });
      });
    };
    const updateComplaintStat = (mode) => {
      queryParam.value.type = mode;
      if (mode == 0) {
        queryParam.value.yearMonth = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY-MM");
        timeStr.value = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年MM月");
      } else {
        queryParam.value.yearMonth = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY");
        timeStr.value = common_vendor.dayjs(/* @__PURE__ */ new Date()).format("YYYY年");
      }
      getComplaintStat();
    };
    const bindPickerChange = (e) => {
      if (e.detail.value.includes("-")) {
        queryParam.value.yearMonth = e.detail.value.split("-")[0] + "-" + e.detail.value.split("-")[1];
        timeStr.value = e.detail.value.split("-")[0] + "年" + e.detail.value.split("-")[1] + "月";
      } else {
        queryParam.value.yearMonth = e.detail.value;
        timeStr.value = e.detail.value + "年";
      }
      getComplaintStat();
    };
    const scanDetail = (row) => {
      common_vendor.index.navigateTo({
        url: `/subPages/leader/reportComplaint/detail?detailInfo=${JSON.stringify(
          row
        )}&type=${queryParam.value.type}&yearMonth=${queryParam.value.yearMonth}`
      });
    };
    common_vendor.onMounted(() => {
    });
    common_vendor.onShow(() => {
      getComplaintStat();
    });
    return (_ctx, _cache) => {
      return common_vendor.e({
        a: common_vendor.n(common_vendor.unref(queryParam).type == 0 ? "opt-btn opt-btn-active" : "opt-btn opt-btn-unactive"),
        b: common_vendor.o(($event) => updateComplaintStat(0)),
        c: common_vendor.n(common_vendor.unref(queryParam).type == 1 ? "opt-btn opt-btn-active" : "opt-btn opt-btn-unactive"),
        d: common_vendor.o(($event) => updateComplaintStat(1)),
        e: common_vendor.p({
          name: "arrow-down",
          color: "#000000",
          size: "18"
        }),
        f: common_vendor.o(($event) => common_vendor.isRef(timeStr) ? timeStr.value = $event : null),
        g: common_vendor.p({
          disabled: true,
          disabledColor: "#ffffff",
          placeholder: "请选择",
          border: "none",
          color: "#000000",
          placeholderStyle: "{color: '#707070'}",
          modelValue: common_vendor.unref(timeStr)
        }),
        h: common_vendor.unref(queryParam).type == 0 ? "month" : "year",
        i: common_vendor.unref(queryParam).yearMonth,
        j: common_vendor.o(bindPickerChange),
        k: common_vendor.o(($event) => showPicker.value = false),
        l: common_vendor.o(($event) => showPicker.value = true),
        m: common_vendor.f(common_vendor.unref(complaintStatistics), (item, index, i0) => {
          return common_vendor.e({
            a: index + 1 != common_vendor.unref(complaintStatistics).length
          }, index + 1 != common_vendor.unref(complaintStatistics).length ? {
            b: common_vendor.t(item.num)
          } : common_vendor.e({
            c: item.num.includes("-")
          }, item.num.includes("-") ? {
            d: common_vendor.unref(common_assets.descendIcon)
          } : {
            e: common_vendor.unref(common_assets.riseIcon)
          }, {
            f: common_vendor.t(item.num.includes("-") ? item.num.substring(1) : item.num)
          }), {
            g: common_vendor.t(item.title),
            h: common_vendor.s(`color:${item.color};background: linear-gradient(180deg, ${item.bgColor0} 0%, ${item.bgColor1} 100%);`),
            i: index,
            j: "984e6ff8-3-" + i0 + ",984e6ff8-2"
          });
        }),
        n: common_vendor.p({
          border: false,
          align: "center",
          gap: "16rpx",
          col: "4"
        }),
        o: common_vendor.unref(queryParam).type == 1
      }, common_vendor.unref(queryParam).type == 1 ? {
        p: common_vendor.p({
          type: "column",
          opts: common_vendor.unref(chartParam).opts,
          tooltipFormat: "normalTooltip",
          chartData: common_vendor.unref(chartParam).chartData,
          ontouch: true
        })
      } : {}, {
        q: common_vendor.p({
          align: "center",
          width: "85"
        }),
        r: common_vendor.p({
          align: "center",
          width: "65"
        }),
        s: common_vendor.p({
          align: "center",
          width: "65"
        }),
        t: common_vendor.p({
          align: "center",
          width: "65"
        }),
        v: common_vendor.t(common_vendor.unref(queryParam).type == 1 ? "同比" : "环比"),
        w: common_vendor.p({
          align: "center",
          width: "40"
        }),
        x: common_vendor.f(common_vendor.unref(tableList), (item, index, i0) => {
          return {
            a: common_vendor.t(item.communityName),
            b: "984e6ff8-13-" + i0 + "," + ("984e6ff8-12-" + i0),
            c: common_vendor.t(item.sumCount),
            d: common_vendor.o(($event) => scanDetail(item), index),
            e: "984e6ff8-14-" + i0 + "," + ("984e6ff8-12-" + i0),
            f: common_vendor.t(item.invalidCount),
            g: "984e6ff8-15-" + i0 + "," + ("984e6ff8-12-" + i0),
            h: common_vendor.t(item.effectiveCount),
            i: "984e6ff8-16-" + i0 + "," + ("984e6ff8-12-" + i0),
            j: common_vendor.t(item.percentage),
            k: "984e6ff8-17-" + i0 + "," + ("984e6ff8-12-" + i0),
            l: index,
            m: "984e6ff8-12-" + i0 + ",984e6ff8-5"
          };
        }),
        y: common_vendor.p({
          align: "center"
        }),
        z: common_vendor.p({
          align: "center"
        }),
        A: common_vendor.p({
          align: "center"
        }),
        B: common_vendor.p({
          align: "center"
        }),
        C: common_vendor.p({
          align: "center"
        }),
        D: common_vendor.sr("table", "984e6ff8-5"),
        E: common_vendor.p({
          border: true,
          stripe: true,
          emptyText: "暂无更多数据"
        }),
        F: common_vendor.sr(uToastRef, "984e6ff8-18", {
          "k": "uToastRef"
        })
      });
    };
  }
});
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-984e6ff8"]]);
wx.createPage(MiniProgramPage);
